package constant.milk.cashbook.insert;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import constant.milk.cashbook.R;
import constant.milk.cashbook.SuperActivity;
import constant.milk.cashbook.asset.CountActivity;
import constant.milk.cashbook.asset.MemoActivity;
import constant.milk.cashbook.asset.MoneyActivity;
import constant.milk.cashbook.bean.BankData;
import constant.milk.cashbook.bean.CategoryMainData;
import constant.milk.cashbook.bean.CategorySubData;
import constant.milk.cashbook.bean.CheckData;
import constant.milk.cashbook.bean.CreditData;
import constant.milk.cashbook.bean.GiftData;
import constant.milk.cashbook.bean.PhoneData;
import constant.milk.cashbook.bean.RealData;
import constant.milk.cashbook.category.CategoryMainListActivity;
import constant.milk.cashbook.category.CategorySubListActivity;
import constant.milk.cashbook.database.DBSelectQuery;
import constant.milk.cashbook.database.DbInsertQuery;
import constant.milk.cashbook.photo.PhotoActivity;
import constant.milk.cashbook.tip.TipMap;
import constant.milk.cashbook.tip.TipInfoActivity;
import constant.milk.cashbook.util.MilkManager;
import constant.milk.cashbook.util.CalendarActivity;
import constant.milk.cashbook.util.MilkUtil;
import constant.milk.cashbook.util.TimeActivity;

public class InsertGiftCardActivity extends SuperActivity
{
	public static final int ASSET_LIST_REQUEST_CODE = 0;
	public static final int COUNT_REQUEST_CODE = 1;
	public static final int CATEGORY_MAIN_REQUEST_CODE = 2;
	public static final int CATEGORY_SUB_REQUEST_CODE = 3;
	public static final int CALENDER_REQUEST_CODE = 4;
	public static final int TIME_REQUEST_CODE = 5;
	public static final int MEMO_REQUEST_CODE = 6;
	public static final int ADD_ASSET_CHOICE_REQUEST_CODE = 7;
	public static final int ADD_ASSET_LIST_REQUEST_CODE = 8;
	public static final int ADD_MONEY_REQUEST_CODE = 9;
	public static final int PHOTO_REQUEST_CODE = 10;
	
	private View useView;
	private View buyView;
	
	private View selectView;
	private View select1View;
	private View select2View;
	private View select3View;
	
	private View assetNameView;
	private TextView assetNameTextView;
	
	private TextView countTextView;
	
	private TextView countMoneyTextView;
	
	private View useCountView;
	private TextView useTitleTextView;
	private TextView useCountTextView;
	
	private TextView totalMoneyTitleTextView;
	private TextView totalMoneyTextView;
	
	private View mainCategoryView;
	private TextView mainCategoryTextView;
	
	private View subCategoryView;
	private TextView subCategoryTextView;
	
	private View dateView;
	private TextView dateTextView;
	
	private View timeView;
	private TextView timeTextView;
	
	private View memoView;
	private TextView memoTextView;
	
	private View photoView;
	private TextView photoTextView;
	
	private View addView;
	private View addAssetView;
	private TextView addAssetTextView;
	private View addAssetNameView;
	private TextView addAssetNameTextView;
	private View addMoneyView;
	private TextView addMoneyTextView;
	
	private TextView addMoneyTitle;
	
	private Button saveButton;
	
	private ArrayList<String> assetNameList;
	private ArrayList<String> addAssetNameList;
	private ArrayList<String> categoryMainList;
	private ArrayList<String> categorySubList;
	
	private DBSelectQuery select;
	
	private int year;
	private int month;
	private int day;
	
	private String am_pm;
	private String hour;
	private String minute;
	
	private MilkManager assetManager;
	
	private int inOutFlag;
	
	private int addChangeFlag;
	
	private String photoPath;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.insert_giftcard_activity);
		
		setTitle("상품권입력");
		
		setFindViewId();
		setOnClick();
		setData();
	}

	@Override
	protected void setFindViewId()
	{
		useView = findViewById(R.id.insertGiftCardOutView);
		buyView = findViewById(R.id.insertGiftCardInView);
		
		selectView = findViewById(R.id.insertGiftCardSelectView);
		select1View = findViewById(R.id.insertGiftCardSelect1View);
		select2View = findViewById(R.id.insertGiftCardSelect2View);
		select3View = findViewById(R.id.insertGiftCardSelect3View);
		
		assetNameView = findViewById(R.id.insertGiftCardAssetNameView);
		assetNameTextView = (TextView) findViewById(R.id.insertGiftCardAssetNameTextView);
		
		countTextView = (TextView) findViewById(R.id.insertGiftCardCountTextView);
		countMoneyTextView = (TextView) findViewById(R.id.insertGiftCardCountMoneyTextView);
		
		useCountView = findViewById(R.id.insertGiftCardUseCountView);
		useTitleTextView = (TextView) findViewById(R.id.insertGiftCardUseTitleTextView);
		useCountTextView = (TextView) findViewById(R.id.insertGiftCardUseCountTextView);
		totalMoneyTitleTextView = (TextView) findViewById(R.id.insertGiftCardTotalMoneyTitleTextView);
		totalMoneyTextView = (TextView) findViewById(R.id.insertGiftCardTotalMoneyTextView);
		
		mainCategoryView = findViewById(R.id.insertGiftCardMainCategoryView);
		mainCategoryTextView = (TextView) findViewById(R.id.insertGiftCardMainCategoryTextView);
		
		subCategoryView = findViewById(R.id.insertGiftCardSubCategoryView);
		subCategoryTextView = (TextView) findViewById(R.id.insertGiftCardSubCategoryTextView);
		
		dateView = findViewById(R.id.insertGiftCardDateView);
		dateTextView = (TextView) findViewById(R.id.insertGiftCardDateTextView);
		
		timeView = findViewById(R.id.insertGiftCardTimeView);
		timeTextView = (TextView) findViewById(R.id.insertGiftCardTimeTextView);
		
		memoView = findViewById(R.id.insertGiftCardMemoView);
		memoTextView = (TextView) findViewById(R.id.insertGiftCardMemoTextView);
		
		photoView = findViewById(R.id.insertGiftCardPhotoView);
		photoTextView = (TextView) findViewById(R.id.insertGiftCardPhotoTextView);
		
		addView = findViewById(R.id.insertGiftCardAddView);
		addAssetView = findViewById(R.id.insertGiftCardAddAssetView);
		addAssetTextView = (TextView) findViewById(R.id.insertGiftCardAddAssetTextView);
		addAssetNameView = findViewById(R.id.insertGiftCardAddAssetNameView);
		addAssetNameTextView = (TextView) findViewById(R.id.insertGiftCardAddAssetNameTextView);
		addMoneyView = findViewById(R.id.insertGiftCardAddMoneyView);
		addMoneyTextView = (TextView) findViewById(R.id.insertGiftCardAddMoneyTextView);
		
		addMoneyTitle = (TextView) findViewById(R.id.insertGiftCardAddMoneyTitle);
		
		saveButton = (Button) findViewById(R.id.saveButton);
	}

	@Override
	protected void setOnClick()
	{
		useView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setUseSelect();
				
				useCountTextView.setText("0");
				
				totalMoneyTextView.setText("0");
			}
		});
		
		buyView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setBuySelect();
				
				useCountTextView.setText("0");
				
				totalMoneyTextView.setText("0");
			}
		});
		
		select1View.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setClearView();
			}
		});
		
		select2View.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setAddView();
			}
		});
		
		select3View.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setChangeView();
			}
		});
		
		assetNameView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				startAssetNameList();
			}
		});
		
		useCountView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent(superContext, CountActivity.class);
				intent.putExtra(CountActivity.COUNT_DATA, useCountTextView.getText().toString());
				intent.putExtra(CountActivity.COUNT_FLAG, 1);
				startActivityForResult(intent, COUNT_REQUEST_CODE);
			}
		});
		
		mainCategoryView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				startCategoryMainList();
			}
		});
		
		subCategoryView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				startCategorySubList();
			}
		});
		
		dateView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				startCalendar();
			}
		});
		
		timeView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				startTime();
			}
		});
		
		memoView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				startMemo();
			}
		});
		
		photoView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent(superContext, PhotoActivity.class);
				intent.putExtra(PhotoActivity.PHOTH_PASH, photoPath);
				startActivityForResult(intent, PHOTO_REQUEST_CODE);
			}
		});
		
		addAssetView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent(superContext, AssetChoiceActivity.class);
				intent.putExtra(AssetChoiceActivity.INSERT_TYPE, AssetChoiceActivity.GIFTCARD);
				intent.putExtra(AssetChoiceActivity.ASSET_CHOICE_DATA, addAssetTextView.getText().toString());
				startActivityForResult(intent, ADD_ASSET_CHOICE_REQUEST_CODE);
			}
		});
		
		addAssetNameView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				startAddAssetNameList();
			}
		});
		
		addMoneyView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				if (inOutFlag == 1)
				{
					MilkUtil.showToast(superContext, "구입금액은 구입갯수로 변경이 가능합니다.");
					return;
				}
				
				Intent intent = new Intent(superContext, MoneyActivity.class);
				intent.putExtra(MoneyActivity.MONEY_DATA, addMoneyTextView.getText().toString());
				startActivityForResult(intent, ADD_MONEY_REQUEST_CODE);
			}
		});
		
		saveButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				if (!checkInsert())
				{
					return;
				}
				
				if (setSaveData())
				{
					MilkUtil.showDialogFinish(superContext, "확인", "데이터 저장에 성공하였습니다.");
				}
				else
				{
					MilkUtil.showDialog(superContext, "실패", "잠시후 다시해 주세요.");
				}
			}
		});
	}

	@Override
	protected void setData()
	{
		assetManager = new MilkManager(superContext, superDb);
		select = new DBSelectQuery(superContext, superDb);
		
		setUseSelect();
		
		setAssetGiftCardData(getString(R.string.giftCardAsset));
		
		setCategoryMain();
		
		setCategorySub();
		
		setNowTime();
		
		setDateView();
		setTimeView();
		
		useCountTextView.setText("0");
		totalMoneyTextView.setText("0");
		
		photoTextView.setText("없음");
		
		photoPath = "";
	}
	
	private void setUseSelect()
	{
		int padding = MilkUtil.dipToPixel(superContext, 10);
		useView.setBackgroundResource(R.drawable.btn_neon_push);
		useView.setPadding(padding, padding, padding, padding);
		buyView.setBackgroundResource(0);
		buyView.setPadding(padding, padding, padding, padding);
		
		selectView.setVisibility(View.VISIBLE);
		setClearView();
		
		inOutFlag = 0;
		
		useTitleTextView.setText("사용갯수");
		totalMoneyTitleTextView.setText("사용금액");
	}
	
	private void setBuySelect()
	{
		int padding = MilkUtil.dipToPixel(superContext, 10);
		buyView.setBackgroundResource(R.drawable.btn_neon_push);
		buyView.setPadding(padding, padding, padding, padding);
		useView.setBackgroundResource(0);
		useView.setPadding(padding, padding, padding, padding);
		
		selectView.setVisibility(View.GONE);
		setBuyView();
		
		inOutFlag = 1;
		
		useTitleTextView.setText("구입갯수");
		totalMoneyTitleTextView.setText("구입금액");
	}
	
	private void setClearView()
	{
		addView.setVisibility(View.GONE);
		
		addChangeFlag = 0;
		
		int padding = MilkUtil.dipToPixel(superContext, 10);
		select1View.setBackgroundResource(R.drawable.btn_neon_push);
		select1View.setPadding(padding, padding, padding, padding);
		select2View.setBackgroundResource(0);
		select2View.setPadding(padding, padding, padding, padding);
		select3View.setBackgroundResource(0);
		select3View.setPadding(padding, padding, padding, padding);
	}
	
	private void setAddView()
	{
		addView.setVisibility(View.VISIBLE);
		
		setAssetNameData(getString(R.string.realAsset));
		
		addAssetTextView.setText(getString(R.string.realAsset));
		
		addAssetView.setClickable(true);
		
		addMoneyTextView.setText("0");
		
		addMoneyTitle.setText(getString(R.string.addMoney));
		
		addChangeFlag = 1;
		
		int padding = MilkUtil.dipToPixel(superContext, 10);
		select2View.setBackgroundResource(R.drawable.btn_neon_push);
		select2View.setPadding(padding, padding, padding, padding);
		select1View.setBackgroundResource(0);
		select1View.setPadding(padding, padding, padding, padding);
		select3View.setBackgroundResource(0);
		select3View.setPadding(padding, padding, padding, padding);
	}
	
	private void setChangeView()
	{
		addView.setVisibility(View.VISIBLE);
		
		setAssetNameData(getString(R.string.realAsset));
		
		addAssetTextView.setText(getString(R.string.realAsset));
		
		addAssetView.setClickable(false);
		
		addMoneyTextView.setText("0");
		
		addMoneyTitle.setText(getString(R.string.changeMoney));
		
		addChangeFlag = 2;
		
		int padding = MilkUtil.dipToPixel(superContext, 10);
		select3View.setBackgroundResource(R.drawable.btn_neon_push);
		select3View.setPadding(padding, padding, padding, padding);
		select1View.setBackgroundResource(0);
		select1View.setPadding(padding, padding, padding, padding);
		select2View.setBackgroundResource(0);
		select2View.setPadding(padding, padding, padding, padding);
	}
	
	private void setBuyView()
	{
		addView.setVisibility(View.VISIBLE);
		
		setAssetNameData(getString(R.string.realAsset));
		
		addAssetTextView.setText(getString(R.string.realAsset));
		
		addAssetView.setClickable(true);
		
		addMoneyTextView.setText("0");
		
		addMoneyTitle.setText(getString(R.string.buyMoney));
		
		addChangeFlag = 0;
	}
	
	private void setNowTime()
	{
		Calendar cal = Calendar.getInstance();
		year = cal.get(Calendar.YEAR);
		month = cal.get(Calendar.MONTH);
		day = cal.get(Calendar.DAY_OF_MONTH);
		
		if (cal.get(Calendar.AM_PM) == Calendar.AM)
		{
			am_pm = "AM";
		}
		else
		{
			am_pm = "PM";
		}
		
		if (cal.get(Calendar.HOUR) == 0)
		{
			hour = "12";
		}
		else
		{
			if (cal.get(Calendar.HOUR) < 10)
			{
				hour = "0" + cal.get(Calendar.HOUR);
			}
			else
			{
				hour = cal.get(Calendar.HOUR) + "";
			}
		}
		
		if (cal.get(Calendar.MINUTE) < 10)
		{
			minute = "0" + cal.get(Calendar.MINUTE);
		}
		else
		{
			minute = cal.get(Calendar.MINUTE) + "";
		}
	}
	
	private boolean checkInsert()
	{
		if (assetNameTextView.getText().toString().equals(""))
		{
			MilkUtil.showToast(superContext, "자산을 추가해 주세요.");
			return false;
		}
		
		if (mainCategoryTextView.getText().toString().equals(""))
		{
			MilkUtil.showToast(superContext, "메인 카테고리를 추가해 주세요.");
			return false;
		}
		
		if (subCategoryTextView.getText().toString().equals(""))
		{
			MilkUtil.showToast(superContext, "서브 카테고리를 추가해 주세요.");
			return false;
		}
		
		if (totalMoneyTextView.getText().toString().equals(""))
		{
			MilkUtil.showToast(superContext, "금액을 정확히 입력해 주세요.");
			return false;
		}
		
		return true;
	}
	
	private boolean setSaveData()
	{
		DbInsertQuery query = null;
		
		try
		{
			query = new DbInsertQuery(superContext, superDb);
			
			query.setBeginTansaction();
			
			HashMap<String, String> map = new HashMap<String, String>();
			
			if (inOutFlag == 0)
			{
				map.put("type", "6");
				
				if (addChangeFlag == 1)
				{
					map.put("kind", "6");
					map.put("subasset", assetManager.getAssetStr(addAssetTextView.getText().toString()));
					map.put("subname", addAssetNameTextView.getText().toString());
					map.put("submoney", MilkUtil.getCommaDel(addMoneyTextView.getText().toString()));
				}
				else if (addChangeFlag == 2)
				{
					map.put("kind", "7");
					map.put("subasset", assetManager.getAssetStr(getString(R.string.realAsset)));
					map.put("subname", addAssetNameTextView.getText().toString());
					map.put("submoney", MilkUtil.getCommaDel(addMoneyTextView.getText().toString()));
				}
				else
				{
					map.put("kind", "5");
				}
			}
			else
			{
				map.put("type", "7");
				
				map.put("subasset", assetManager.getAssetStr(addAssetTextView.getText().toString()));
				map.put("subname", addAssetNameTextView.getText().toString());
				map.put("submoney", MilkUtil.getCommaDel(addMoneyTextView.getText().toString()));
			}
			
			map.put("asset", assetManager.getAssetStr(getString(R.string.giftCardAsset)));
			map.put("name", assetNameTextView.getText().toString());
			map.put("money", MilkUtil.getCommaDel(totalMoneyTextView.getText().toString()));
			map.put("maincategory", mainCategoryTextView.getText().toString());
			map.put("subcategory", subCategoryTextView.getText().toString());
			map.put("date", MilkUtil.getDateDB(year, month+1, day));
			map.put("ampm", MilkUtil.getAmPm(am_pm));
			map.put("timehour", hour);
			map.put("timeminute", minute);
			map.put("memo", memoTextView.getText().toString());
			map.put("photopath", photoPath);
			
			query.setInOut(map);
			
			MilkManager rollBank = new MilkManager(superContext, superDb);
			
			if (inOutFlag == 0)
			{
				rollBank.setAssetMoney(getString(R.string.giftCardAsset), assetNameTextView.getText().toString(),
						useCountTextView.getText().toString(), 0);
				
				if (addChangeFlag == 1)
				{
					rollBank.setAssetMoney(addAssetTextView.getText().toString(), 
							addAssetNameTextView.getText().toString(),
							addMoneyTextView.getText().toString(), 0);
				}
				else if (addChangeFlag == 2)
				{
					rollBank.setAssetMoney(getString(R.string.realAsset), 
							addAssetNameTextView.getText().toString(),
							addMoneyTextView.getText().toString(), 1);
				}
			}
			else
			{
				rollBank.setAssetMoney(getString(R.string.giftCardAsset), assetNameTextView.getText().toString(),
						useCountTextView.getText().toString(), 1);
				
				rollBank.setAssetMoney(addAssetTextView.getText().toString(), 
						addAssetNameTextView.getText().toString(),
						addMoneyTextView.getText().toString(), 0);
			}
			
			query.setSuccessful();
		} catch (Exception e)
		{
			e.printStackTrace();
			return false;
		} finally {
			try
			{
				query.setEndTansaction();
			} catch (Exception e)
			{
				e.printStackTrace();
				return false;
			}
		}
		
		return true;
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data)
	{
		super.onActivityResult(requestCode, resultCode, data);
		
		if (resultCode != Activity.RESULT_OK)
		{
			return;
		}
		
		if (requestCode == ASSET_LIST_REQUEST_CODE)
		{
			String str = data.getStringExtra(AssetListActivity.ASSET_NAME_DATA);
			assetNameTextView.setText(str);
			
			GiftData giftData = select.getGiftName(str);
			
			countTextView.setText(giftData.getNumber());
			countMoneyTextView.setText(MilkUtil.getWon(giftData.getMoney()));
		}
		else if (requestCode == COUNT_REQUEST_CODE)
		{
			String str = data.getStringExtra(CountActivity.COUNT_DATA);
			
			int useCount = Integer.parseInt(str);
			
			useCountTextView.setText(str);
			
			BigDecimal totalMoney = BigDecimal.ZERO;
			BigDecimal useC = new BigDecimal(useCount);
			
			totalMoney = useC.multiply(new BigDecimal(MilkUtil.getCommaDel(countMoneyTextView.getText().toString())));
			
			totalMoneyTextView.setText(MilkUtil.getWon(totalMoney.toString()));
			
			if (inOutFlag == 1)
			{
				addMoneyTextView.setText(MilkUtil.getWon(totalMoney.toString()));
			}
		}
		else if (requestCode == CATEGORY_MAIN_REQUEST_CODE)
		{
			String str = data.getStringExtra(CategoryMainListActivity.CATEGORY_MAIN_NAME_DATA);
			mainCategoryTextView.setText(str);
			
			setCategorySub();
			
		}
		else if (requestCode == CATEGORY_SUB_REQUEST_CODE)
		{
			String str = data.getStringExtra(CategorySubListActivity.CATEGORY_SUB_NAME_DATA);
			subCategoryTextView.setText(str);
			
		}
		else if (requestCode == CALENDER_REQUEST_CODE)
		{
			Calendar cal = Calendar.getInstance();
			year = data.getIntExtra(CalendarActivity.YEAR, cal.get(Calendar.YEAR));
			month = data.getIntExtra(CalendarActivity.MONTN, cal.get(Calendar.MONTH));
			day = data.getIntExtra(CalendarActivity.DAY, cal.get(Calendar.DAY_OF_MONTH));
			setDateView();
			
		}
		else if (requestCode == TIME_REQUEST_CODE)
		{
			am_pm = data.getStringExtra(TimeActivity.TIME_AM_PM_DATA);
			hour = data.getStringExtra(TimeActivity.TIME_HOUR_DATA);
			minute = data.getStringExtra(TimeActivity.TIME_MINUTE_DATA);
			setTimeView();
			
		}
		else if (requestCode == MEMO_REQUEST_CODE)
		{
			String memo = data.getStringExtra(MemoActivity.MEMO_DATA);
			
			memoTextView.setText(memo);
		}
		else if (requestCode == ADD_ASSET_CHOICE_REQUEST_CODE)
		{
			String str = data.getStringExtra(AssetChoiceActivity.ASSET_CHOICE_DATA);
			addAssetTextView.setText(str);
			
			setAssetNameData(str);
			
		}
		else if (requestCode == ADD_ASSET_LIST_REQUEST_CODE)
		{
			String str = data.getStringExtra(AssetListActivity.ASSET_NAME_DATA);
			addAssetNameTextView.setText(str);
			
		}
		else if (requestCode == ADD_MONEY_REQUEST_CODE)
		{
			String money = data.getStringExtra(MoneyActivity.MONEY_DATA);
			
			addMoneyTextView.setText(money);
		}
		else if (requestCode == PHOTO_REQUEST_CODE)
		{
			String path = data.getStringExtra(PhotoActivity.PHOTH_PASH);
			
			photoPath = path;
			
			if (photoPath.equals(""))
			{
				photoTextView.setText("없음");
			}
			else
			{
				photoTextView.setText("있음");
			}
		}
	}
	
	private void startAssetNameList()
	{
		Intent intent = new Intent(superContext, AssetListActivity.class);
		intent.putExtra(AssetListActivity.ASSET_NAME_DATA, assetNameTextView.getText().toString());
		intent.putExtra(AssetListActivity.ASSET_TYPE_DATA, getString(R.string.giftCardAsset));
		startActivityForResult(intent, ASSET_LIST_REQUEST_CODE);
	}
	
	private void startAddAssetNameList()
	{
		Intent intent = new Intent(superContext, AssetListActivity.class);
		intent.putExtra(AssetListActivity.ASSET_NAME_DATA, addAssetNameTextView.getText().toString());
		intent.putExtra(AssetListActivity.ASSET_TYPE_DATA, addAssetTextView.getText().toString());
		startActivityForResult(intent, ADD_ASSET_LIST_REQUEST_CODE);
	}
	
	private void startCategoryMainList()
	{
		Intent intent = new Intent(superContext, CategoryMainListActivity.class);
		intent.putExtra(CategoryMainListActivity.CATEGORY_MAIN_NAME_DATA, mainCategoryTextView.getText().toString());
		intent.putExtra(CategoryMainListActivity.CATEGORY_MAIN_LIST_DATA, categoryMainList);
		startActivityForResult(intent, CATEGORY_MAIN_REQUEST_CODE);
	}
	
	private void startCategorySubList()
	{
		Intent intent = new Intent(superContext, CategorySubListActivity.class);
		intent.putExtra(CategorySubListActivity.CATEGORY_MAIN_NAME_DATA, mainCategoryTextView.getText().toString());
		intent.putExtra(CategorySubListActivity.CATEGORY_SUB_NAME_DATA, subCategoryTextView.getText().toString());
		intent.putExtra(CategorySubListActivity.CATEGORY_SUB_LIST_DATA, categorySubList);
		startActivityForResult(intent, CATEGORY_SUB_REQUEST_CODE);
	}
	
	private void startCalendar()
	{
		Intent intent = new Intent(superContext, CalendarActivity.class);
		intent.putExtra(CalendarActivity.YEAR, year);
		intent.putExtra(CalendarActivity.MONTN, month);
		intent.putExtra(CalendarActivity.DAY, day);
		startActivityForResult(intent, CALENDER_REQUEST_CODE);
	}
	
	private void startTime()
	{
		Intent intent = new Intent(superContext, TimeActivity.class);
		intent.putExtra(TimeActivity.TIME_AM_PM_DATA, am_pm);
		intent.putExtra(TimeActivity.TIME_HOUR_DATA, hour);
		intent.putExtra(TimeActivity.TIME_MINUTE_DATA, minute);
		startActivityForResult(intent, TIME_REQUEST_CODE);
	}
	
	private void startMemo()
	{
		Intent intent = new Intent(superContext, MemoActivity.class);
		intent.putExtra(MemoActivity.MEMO_DATA, memoTextView.getText().toString());
		startActivityForResult(intent, MEMO_REQUEST_CODE);
	}

	private void setAssetNameData(String str)
	{
		DBSelectQuery query = new DBSelectQuery(superContext, superDb);
		
		addAssetNameList = new ArrayList<String>();
		
		if (str.equals(getString(R.string.realAsset)))
		{
			ArrayList<RealData> list = query.getRealList();
			
			if (list == null || list.size() < 1)
			{
				addAssetNameTextView.setText("");
				addAssetNameTextView.setHint("현금을 추가해주세요.");
				return;
			}
			
			addAssetNameTextView.setText(list.get(0).getName());
			
			for (int i = 0; i < list.size(); i++)
			{
				addAssetNameList.add(list.get(i).getName());
			}
		}
		else if (str.equals(getString(R.string.bankAsset)))
		{
			ArrayList<BankData> list = query.getBankList();
			
			if (list == null || list.size() < 1)
			{
				addAssetNameTextView.setText("");
				addAssetNameTextView.setHint("통장을 추가해주세요.");
				return;
			}
			
			addAssetNameTextView.setText(list.get(0).getName());
			
			for (int i = 0; i < list.size(); i++)
			{
				addAssetNameList.add(list.get(i).getName());
			}
		}
		else if (str.equals(getString(R.string.checkCardAsset)))
		{
			ArrayList<CheckData> list = query.getCheckList();
			
			if (list == null || list.size() < 1)
			{
				addAssetNameTextView.setText("");
				addAssetNameTextView.setHint("체크카드를 추가해주세요.");
				return;
			}
			
			addAssetNameTextView.setText(list.get(0).getName());
			
			for (int i = 0; i < list.size(); i++)
			{
				addAssetNameList.add(list.get(i).getName());
			}
		}
		else if (str.equals(getString(R.string.creditCardAsset)))
		{
			ArrayList<CreditData> list = query.getCreditList();
			
			if (list == null || list.size() < 1)
			{
				addAssetNameTextView.setText("");
				addAssetNameTextView.setHint("신용카드를 추가해주세요.");
				return;
			}
			
			addAssetNameTextView.setText(list.get(0).getName());
			
			for (int i = 0; i < list.size(); i++)
			{
				addAssetNameList.add(list.get(i).getName());
			}
		}
		else if (str.equals(getString(R.string.phoneAsset)))
		{
			ArrayList<PhoneData> list = query.getPhoneList();
			
			if (list == null || list.size() < 1)
			{
				addAssetNameTextView.setText("");
				addAssetNameTextView.setHint("핸드폰을 추가해주세요.");
				return;
			}
			
			addAssetNameTextView.setText(list.get(0).getName());
			
			for (int i = 0; i < list.size(); i++)
			{
				addAssetNameList.add(list.get(i).getName());
			}
		}
		else if (str.equals(getString(R.string.giftCardAsset)))
		{
			ArrayList<GiftData> list = query.getGiftList();
			
			if (list == null || list.size() < 1)
			{
				addAssetNameTextView.setText("");
				addAssetNameTextView.setHint("상품권을 추가해주세요.");
				return;
			}
			
			addAssetNameTextView.setText(list.get(0).getName());
			
			for (int i = 0; i < list.size(); i++)
			{
				addAssetNameList.add(list.get(i).getName());
			}
			
			countTextView.setText(list.get(0).getNumber());
			countMoneyTextView.setText(MilkUtil.getWon(list.get(0).getMoney()));
		}
	}
	
	private void setAssetGiftCardData(String str)
	{
		DBSelectQuery query = new DBSelectQuery(superContext, superDb);
		
		assetNameList = new ArrayList<String>();
		
		if (str.equals(getString(R.string.realAsset)))
		{
			ArrayList<RealData> list = query.getRealList();
			
			if (list == null || list.size() < 1)
			{
				assetNameTextView.setText("");
				assetNameTextView.setHint("현금을 추가해주세요.");
				return;
			}
			
			assetNameTextView.setText(list.get(0).getName());
			
			for (int i = 0; i < list.size(); i++)
			{
				assetNameList.add(list.get(i).getName());
			}
		}
		else if (str.equals(getString(R.string.bankAsset)))
		{
			ArrayList<BankData> list = query.getBankList();
			
			if (list == null || list.size() < 1)
			{
				assetNameTextView.setText("");
				assetNameTextView.setHint("통장을 추가해주세요.");
				return;
			}
			
			assetNameTextView.setText(list.get(0).getName());
			
			for (int i = 0; i < list.size(); i++)
			{
				assetNameList.add(list.get(i).getName());
			}
		}
		else if (str.equals(getString(R.string.checkCardAsset)))
		{
			ArrayList<CheckData> list = query.getCheckList();
			
			if (list == null || list.size() < 1)
			{
				assetNameTextView.setText("");
				assetNameTextView.setHint("체크카드를 추가해주세요.");
				return;
			}
			
			assetNameTextView.setText(list.get(0).getName());
			
			for (int i = 0; i < list.size(); i++)
			{
				assetNameList.add(list.get(i).getName());
			}
		}
		else if (str.equals(getString(R.string.creditCardAsset)))
		{
			ArrayList<CreditData> list = query.getCreditList();
			
			if (list == null || list.size() < 1)
			{
				assetNameTextView.setText("");
				assetNameTextView.setHint("신용카드를 추가해주세요.");
				return;
			}
			
			assetNameTextView.setText(list.get(0).getName());
			
			for (int i = 0; i < list.size(); i++)
			{
				assetNameList.add(list.get(i).getName());
			}
		}
		else if (str.equals(getString(R.string.phoneAsset)))
		{
			ArrayList<PhoneData> list = query.getPhoneList();
			
			if (list == null || list.size() < 1)
			{
				assetNameTextView.setText("");
				assetNameTextView.setHint("핸드폰을 추가해주세요.");
				return;
			}
			
			assetNameTextView.setText(list.get(0).getName());
			
			for (int i = 0; i < list.size(); i++)
			{
				assetNameList.add(list.get(i).getName());
			}
		}
		else if (str.equals(getString(R.string.giftCardAsset)))
		{
			ArrayList<GiftData> list = query.getGiftList();
			
			if (list == null || list.size() < 1)
			{
				assetNameTextView.setText("");
				assetNameTextView.setHint("상품권을 추가해주세요.");
				return;
			}
			
			assetNameTextView.setText(list.get(0).getName());
			
			for (int i = 0; i < list.size(); i++)
			{
				assetNameList.add(list.get(i).getName());
			}
			
			countTextView.setText(list.get(0).getNumber());
			countMoneyTextView.setText(MilkUtil.getWon(list.get(0).getMoney()));
		}
	}
	
	private void setCategoryMain()
	{
		ArrayList<CategoryMainData> list = select.getCategoryMainList();
		
		if (list == null || list.size() < 1)
		{
			mainCategoryTextView.setText("");
			mainCategoryTextView.setHint("카테고리를 추가해주세요.");
			return;
		}
		
		mainCategoryTextView.setText(list.get(0).getName());
		
		categoryMainList = new ArrayList<String>();
		
		for (int i = 0; i < list.size(); i++)
		{
			categoryMainList.add(list.get(i).getName());
		}
	}
	
	private void setCategorySub()
	{
		if (mainCategoryTextView.getText().toString().equals(""))
		{
			subCategoryTextView.setText("");
			subCategoryTextView.setHint("카테고리를 추가해주세요.");
			return;
		}
		
		CategoryMainData data = select.getCategoryMainName(mainCategoryTextView.getText().toString());
		
		ArrayList<CategorySubData> list = select.getCategorySubList(data.getId());
		
		if (list == null || list.size() < 1)
		{
			subCategoryTextView.setText("");
			subCategoryTextView.setHint("카테고리를 추가해주세요.");
			return;
		}
		
		subCategoryTextView.setText(list.get(0).getName());
		
		categorySubList = new ArrayList<String>();
		
		for (int i = 0; i < list.size(); i++)
		{
			categorySubList.add(list.get(i).getName());
		}
	}
	
	private void setDateView()
	{
		dateTextView.setText(MilkUtil.getDate(year, month+1, day));
	}
	
	private void setTimeView()
	{
		timeTextView.setText(MilkUtil.getTime(am_pm, hour, minute));
	}

	@Override
	protected void tipButton()
	{
		Intent intent = new Intent(superContext, TipInfoActivity.class);
		intent.putExtra(TipInfoActivity.TIP_ID, TipMap.TIP_INSERT_GIFTCARD);
		startActivity(intent);
	}

}
